﻿// --------------------------------------------------------------------------------------------------------------------
// <summary>
//   http://nesteruk.wordpress.com/2010/07/18/c-sharp-pattern-matching/
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System;

namespace Security.Helpers
{
    public static class MatchExtensions
    {
        public static T Match<T>(this T target, Predicate<T> predicate, Action<T> whenMatched)
        {
            if (predicate(target))
                whenMatched(target);
            return target;
        }

        public static T Match<T>(this T target, T value, Action<T> whenMatched)
        {
            if (target.Equals(value))
                whenMatched(target);
            return target;
        }

        public static T Match<T>(this T target, T value, Action whenMatched)
        {
            if (target.Equals(value))
                whenMatched();
            return target;
        }
    }
}
